package top.wuyang.springboot3.schoolTimetable.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import top.wuyang.springboot3.base.PageBean;
import top.wuyang.springboot3.base.R;
import top.wuyang.springboot3.schoolTimetable.entity.TbTeacherInfo;
import top.wuyang.springboot3.schoolTimetable.service.TbTeacherInfoService;
import top.wuyang.springboot3.validate.CommonValidate;
import top.wuyang.springboot3.vo.PageVO;

@RestController
@RequestMapping("/teacherInfo")
@RequiredArgsConstructor
public class TbTeacherInfoController {

    private final TbTeacherInfoService tbTeacherInfoService;

    @GetMapping("/{pn}/{ps}")
    public R<PageVO<TbTeacherInfo>> query(TbTeacherInfo tbTeacherInfo, @PathVariable("pn") Long pageNumber, @PathVariable("ps") Long pageSize) {
        return tbTeacherInfoService.query(tbTeacherInfo, PageBean.instance(pageNumber, pageSize));
    }

    @GetMapping("/{id}")
    public R<TbTeacherInfo> queryById(@PathVariable("id") Integer id) {
        return tbTeacherInfoService.queryById(id);
    }

    @PostMapping("")
    public R<String> insert(@RequestBody @Validated(CommonValidate.Add.class) TbTeacherInfo tbTeacherInfo) {
        return tbTeacherInfoService.insert(tbTeacherInfo);
    }

    @PutMapping("")
    public R<String> update(@RequestBody @Validated(CommonValidate.Edit.class) TbTeacherInfo tbTeacherInfo) {
        return tbTeacherInfoService.update(tbTeacherInfo);
    }

    @DeleteMapping("/{id}")
    public R<String> delete(@PathVariable("id") Integer id) {
        return tbTeacherInfoService.delete(id);
    }



}
